package com.example.system.controller;

import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.R;
import com.example.common.core.domain.TableDataInfo;
import com.example.system.domain.course.dto.CourseQueryDTO;
import com.example.system.domain.course.dto.CourseSaveDTO;
import com.example.system.domain.course.dto.CourseStatusUpdateDTO;
import com.example.system.domain.course.vo.CourseDetailVO;
import com.example.system.service.ICourseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
@Tag(name = "课程管理接口")
public class CourseController extends BaseController {
    @Autowired
    private ICourseService courseService;

    //  /Course/add
    @PostMapping("/add")
    @Operation(summary = "添加课程")
    public R<Void> add(@RequestBody CourseSaveDTO courseAddDTO) {
        return toR(courseService.add(courseAddDTO));
    }

    @GetMapping("/list")
    @Operation(summary = "查询课程列表")
    public TableDataInfo list(CourseQueryDTO courseQueryDTO) {
        return getTableDataInfo(courseService.list(courseQueryDTO));
    }

    //  /Course/detail
    @GetMapping("/detail")
    @Operation(summary = "查询课程详情")
    public R<CourseDetailVO> detail(Long courseId) {
        return R.ok(courseService.detail(courseId));
    }

    //  /Course/edit
    @PutMapping("/edit")
    @Operation(summary = "编辑课程")
    public R<Void> edit(@RequestBody CourseSaveDTO courseSaveDTO) {
        return toR(courseService.edit(courseSaveDTO));
    }

    //  /Course/delete
    @DeleteMapping("/delete")
    @Operation(summary = "删除课程")
    public R<Void> delete(Long courseId) {
        return toR(courseService.delete(courseId));
    }
    
    /**
     * 获取待审核的课程列表
     */
    @GetMapping("/pending-review")
    @Operation(summary = "获取待审核课程列表")
    public TableDataInfo getPendingReviewCourses(CourseQueryDTO courseQueryDTO) {
        return getTableDataInfo(courseService.getPendingReviewCourses(courseQueryDTO));
    }
    
    /**
     * 审核课程（通过或驳回）
     */
    @PutMapping("/review")
    @Operation(summary = "审核课程")
    public R<String> reviewCourse(@RequestBody CourseStatusUpdateDTO courseStatusUpdateDTO) {
        return courseService.reviewCourse(courseStatusUpdateDTO);
    }
}
